<template>
    <div class="nav-bar" :class="{'is_fixed': isFixed}">
        <div class="container">
            <div class="pro-title">{{title}}</div>
            <div class="pro-param">
                <a href="">概述</a><span>|</span>
                <a href="">参数</a><span>|</span>
                <a href="">用户评价</a>
                <slot name="buy"></slot>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "ProductParam",
        props: {
            title: String,
        },
        data() {
            return {
                isFixed: false
            }
        },
        mounted() {
            window.addEventListener('scroll', this.initHeight);
        },
        methods: {
            initHeight() {
                let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;    // 兼容写法
                this.isFixed = scrollTop > 152 ? true : false;
            }
        },
        destroyed() {
            window.removeEventListener('scroll', this.initHeight, false); // 当该组件被销毁后也要销毁该方法，防止在其他页面也生效
        }
    }
</script>

<style scoped lang="scss">
    @import 'assets/scss/config.scss';
    @import 'assets/scss/mixin.scss';

    .nav-bar {
        height: 70px;
        line-height: 70px;
        border-top: 1px solid #e5e5e5;
        background-color: #fff;
        box-shadow: 0 5px 5px rgba(0, 0, 0, .2);
        z-index: 12;

        &.is_fixed {
            position: fixed;
            top: 0;
            width: 100%;
        }

        .container {
            @include flex();

            .pro-title {
                font-size: $fontH;
                color: #333;
                font-weight: bold;
            }

            .pro-param {
                font-size: $fontJ;

                a {
                    color: $colorC;
                }

                span {
                    margin: 0 10px;
                }
            }
        }
    }
</style>
